
* *********************************************************** *;
* *********************************************************** *;
* "Strategic Logic of Elite Purges in Dictatorships"          *;   
* CPS Forthcoming                                             *;
* Jun Koga Sudduth (November 2016)                            *;
* jun.koga@strath.ac.uk                                       *;
* *********************************************************** *; 
* *********************************************************** *;

use "C:\Users\Jun\Dropbox\Elite Purge Project\CPS Final\CPS_Elitepurge_Sudduth.dta", clear  
xtset leadid2 year
 
 
**
** Table 1 (Coup Replacement Model) 
**

* Model 1   
logit coupexit  lrgdpch  logmilex   mildic royal party   failedcoup2_1    coupentry2 logt couplog,  robust cluster(ccode) 

* Model 2 
logit coupexit  IS_WAR chrgdpch lrgdpch  logmilex   mildic royal party  failedcoup2_1   coupentry2 logt couplog ,  robust cluster(ccode) 

* Model 3 
logit coupexit purge4  IS_WAR  chrgdpch lrgdpch  logmilex   mildic royal party  failedcoup2_1   coupentry2 logt couplog ,   robust cluster(ccode) 

* Model 4
logit coupexit Bolivia IS_WAR  chrgdpch lrgdpch  logmilex   mildic royal party  failedcoup2_1   coupentry2 logt couplog ,  robust cluster(ccode) 

* Model 5 
logit coupexit Bolivia purge4 IS_WAR chrgdpch lrgdpch  logmilex   mildic royal party  failedcoup2_1    coupentry2 logt couplog ,  robust cluster(ccode) 
  
* Figure 1 (Using in R)
  
logit coupexit Bolivia IS_WAR  chrgdpch lrgdpch  logmilex   mildic royal party  failedcoup2_1   coupentry2 logt couplog ,  robust cluster(ccode) 

drawnorm a b c d e f g h i j k l m    , n(10000) means(e(b)) cov(e(V)) clear

* I saved this variance-covariance matrix in the csv format to use it in R. Note that you need to move the last column (constnat) 
* to the first column.  


**                                              
** Table 2 (Coup Entry and Elite Elimination)    
**                                              

* Model 1 
logit  purge4    logmilex IS_WAR    lrgdpch  mildic royal party  failedcoup2   purge4yrs purge4yrs2 purge4yrs3  coupentry2 logt couplog,  robust cluster(ccode)  

* Model 2 
logit  purge4 pastpurge4  logmilex IS_WAR   lrgdpch mildic royal  party failedcoup2   purge4yrs purge4yrs2 purge4yrs3  coupentry2 logt couplog,   robust cluster(ccode) 
 
* Model 3 
logit  purge9   logmilex     IS_WAR   lrgdpch    mildic royal  party    failedcoup2   purge9yrs purge9yrs2 purge9yrs3    coupentry2 logt couplog,   robust cluster(ccode) 

* Model 4 
logit  purge9   pastpurge4   logmilex  IS_WAR  lrgdpch    mildic royal party   failedcoup2   purge9yrs purge9yrs2 purge9yrs3  coupentry2 logt couplog,  robust cluster(ccode) 

 
* Figure 2 (Exporting to R)

logit  purge4    logmilex IS_WAR    lrgdpch  mildic royal party  failedcoup2   purge4yrs purge4yrs2 purge4yrs3  coupentry2 logt couplog,  robust cluster(ccode)  
 
drawnorm a b c d e f g h i j k l m n   , n(10000) means(e(b)) cov(e(V)) clear

 

**
** Table 3 (Coup Replacement and Elite Elimination ) 
** 

* Model 1 & 3 (Table 3)

use "C:\Users\Jun\Dropbox\Elite Purge Project\CPS Final\CPS_Elitepurge_Sudduth.dta", clear  

logit coupexit   lrgdpch  logmilex   mildic royal party  failedcoup2_1   coupentry2 logt couplog ,  robust cluster(ccode) 

predict p1, pr
 
save "C:\Users\Jun\Dropbox\Elite Purge Project\Data\p1.dta", replace
  
collapse (mean) meanp1=p1  (median) medianp1=p1 (max) maxp1=p1 , by(ccode)
sort ccode
 
save "C:\Users\Jun\Dropbox\Elite Purge Project\Data\mean.dta", replace
*MERGE INTO BASE*

use "C:\Users\Jun\Dropbox\Elite Purge Project\Data\p1.dta", clear
sort ccode
merge ccode using "C:\Users\Jun\Dropbox\Elite Purge Project\Data\mean.dta", nokeep
drop _merge  

gen dp1 =  p1 - meanp1
gen dp1med= p1- medianp1 
gen dp1max= p1 - maxp1 
 
sort leadid2 year 
by leadid2: gen lag1p1 = p1[_n-1]
by leadid2: gen lag1dp1 = dp1[_n-1]

gen lag1dp1med= lag1p1- medianp1 

 
* Model 1  
logit purge4  dp1med medianp1  IS_WAR  lrgdpch  mildic royal  party   purge4yrs  purge4yrs2 purge4yrs3  ,   vce(bootstrap, rep(100))  
  
* Model 3 
ologit purge4size3 dp1med  medianp1  lrgdpch  IS_WAR mildic royal  party  purge4yrs  purge4yrs2 purge4yrs3   ,vce(bootstrap, rep(100))

test _b[/cut1]=_b[/cut2]
test _b[/cut2]=_b[/cut3]  

ologit purge4size3 dp1med  medianp1  lrgdpch  IS_WAR mildic royal  party  purge4yrs  purge4yrs2 purge4yrs3   , or vce(bootstrap, rep(100))
 
**
** Appendix F
** 

**
** Table 11 

logit purge4  dp1med medianp1  IS_WAR  lrgdpch  mildic royal  party   purge4yrs  purge4yrs2 purge4yrs3 if polity <6 & polity!=-88 & polity!=-77 & polity!=-66 ,   vce(bootstrap, rep(100))

logit purge4  dp1med medianp1  IS_WAR  lrgdpch  mildic royal  party   purge4yrs  purge4yrs2 purge4yrs3 if polity < -5 & polity!=-88 & polity!=-77 & polity!=-66 ,   vce(bootstrap, rep(100))
 
logit purge4  dp1med medianp1  IS_WAR  lrgdpch  mildic royal  party   purge4yrs  purge4yrs2 purge4yrs3  if gwf_nonautocracy2 != 1 & gwf_nonautocracy2 != 3 & gwf_nonautocracy2 != 4   , vce(bootstrap, rep(100))
 

ologit purge4size3 dp1med  medianp1  lrgdpch  IS_WAR mildic royal  party   purge4yrs  purge4yrs2 purge4yrs3 if polity <6 & polity!=-88 & polity!=-77 & polity!=-66 ,  vce(bootstrap, rep(100))

test _b[/cut1]=_b[/cut2]
test _b[/cut2]=_b[/cut3]
  
ologit purge4size3 dp1med  medianp1  lrgdpch  IS_WAR mildic royal  party  purge4yrs  purge4yrs2 purge4yrs3 if polity <6 & polity!=-88 & polity!=-77 & polity!=-66 , or vce(bootstrap, rep(100))

ologit purge4size3 dp1med  medianp1  lrgdpch  IS_WAR mildic royal  party   purge4yrs  purge4yrs2 purge4yrs3 if polity < -5 & polity!=-88 & polity!=-77 & polity!=-66 ,  vce(bootstrap, rep(100))

test _b[/cut1]=_b[/cut2]
test _b[/cut2]=_b[/cut3]
  
ologit purge4size3 dp1med  medianp1  lrgdpch  IS_WAR mildic royal  party  purge4yrs  purge4yrs2 purge4yrs3 if polity < -5 & polity!=-88 & polity!=-77 & polity!=-66 , or vce(bootstrap, rep(100))

ologit purge4size3 dp1med  medianp1  lrgdpch  IS_WAR mildic royal  party  purge4yrs  purge4yrs2 purge4yrs3 if gwf_nonautocracy2 != 1 & gwf_nonautocracy2 != 3 & gwf_nonautocracy2 != 4   ,vce(bootstrap, rep(100))

test _b[/cut1]=_b[/cut2]
test _b[/cut2]=_b[/cut3]
  
  
ologit purge4size3 dp1med  medianp1  lrgdpch  IS_WAR mildic royal  party  purge4yrs  purge4yrs2 purge4yrs3 if gwf_nonautocracy2 != 1 & gwf_nonautocracy2 != 3 & gwf_nonautocracy2 != 4   ,or vce(bootstrap, rep(100))
 

** 
** Appendix D
** 

**
** Table 7 (Models 1, 3 and 5)
  
logit purge4  dp1  meanp1   IS_WAR  lrgdpch  mildic royal  party  purge4yrs  purge4yrs2 purge4yrs3  ,   vce(bootstrap, rep(100))

  	
logit purge9  dp1med medianp1  IS_WAR  lrgdpch  mildic royal  party  purge9yrs  purge9yrs2 purge9yrs3    ,   vce(bootstrap, rep(100))

ologit purge9size3 dp1med  medianp1  lrgdpch  IS_WAR mildic royal  party  purge9yrs  purge9yrs2 purge9yrs3   ,vce(bootstrap, rep(100))

test _b[/cut1]=_b[/cut2]
test _b[/cut2]=_b[/cut3]
  
ologit purge9size3 dp1med  medianp1  lrgdpch  IS_WAR mildic royal  party  purge9yrs  purge9yrs2 purge9yrs3   ,or vce(bootstrap, rep(100))
 

**
** Table 8   
**

drop b*    
estsimp logit purge4  dp1med medianp1  IS_WAR  lrgdpch  mildic royal  party   purge4yrs  purge4yrs2 purge4yrs3  ,   vce(bootstrap, rep(100))  sims(10000) 
sum dp1med, detail 
           

* Pr(Purge) when "dp1med" has the value 5 % percentile 

setx  dp1med    -.0103692     
simqi 
  
* Pr(Purge) when "dp1med" has the value 95 % percentile 

setx  dp1med    .0854215   
simqi 
  
* 95  % percentile => 5 percentile) 
setx 
simqi, fd(pr) changex(dp1med    .0854215    -.0103692  ) level(95) 
 
           
* percentage difference
display (  .7354195 - .5422857     )/(  .5422857     )*100
*  35.61476
 


** 
** Orderd Model 

drop b* 
estsimp ologit purge4size3 dp1med  medianp1  lrgdpch  IS_WAR mildic royal  party  purge4yrs  purge4yrs2 purge4yrs3   ,vce(bootstrap, rep(100))   sims(10000) 


sum dp1med, detail 
          

** 
** 5% ==> 95 Percentile  
**  

* 5 % 
setx dp1med   -.0103692     
simqi  
 
* 95 % 
setx  dp1med   .0854215  
simqi  
   
      
* First differene  
setx  
simqi, fd(pr) changex(dp1med      .0854215   -.0103692    ) level(95) 
 	 
* high ranked purge 
 display (   .5619378 -        .3688975   )/(      .3688975  )*100
 *52.32898%
* middle rank purge 
 display (     .0917376     -      .099708   )/(   .099708 )*100
* -7.9937417
* low ranking purge 
 display (       .0057378 -     .0066854    )/(.0066854     )*100
*-14.174171
  
    
 
  
  
  
**
** Main Text Result 
** 

** 
** Table 3  

* Model 2 and 4   
use "C:\Users\Jun\Dropbox\Elite Purge Project\CPS Final\CPS_Elitepurge_Sudduth.dta", clear  

logit coupexit  IS_WAR chrgdpch lrgdpch  logmilex   mildic royal party  failedcoup2_1   coupentry2 logt couplog ,  robust cluster(ccode) 

predict p1, pr
 
save "C:\Users\Jun\Dropbox\Elite Purge Project\Data\p1.dta", replace
  
collapse (mean) meanp1=p1  (median) medianp1=p1 (max) maxp1=p1 , by(ccode)
sort ccode
 
save "C:\Users\Jun\Dropbox\Elite Purge Project\Data\mean.dta", replace
*MERGE INTO BASE*

use "C:\Users\Jun\Dropbox\Elite Purge Project\Data\p1.dta", clear
sort ccode
merge ccode using "C:\Users\Jun\Dropbox\Elite Purge Project\Data\mean.dta", nokeep
drop _merge  

gen dp1 =  p1 - meanp1
gen dp1med= p1- medianp1 
gen dp1max= p1 - maxp1 
 
sort leadid2 year 
by leadid2: gen lag1p1 = p1[_n-1]
by leadid2: gen lag1dp1 = dp1[_n-1]
 

* Model 2 in Table 3 
 
logit purge4  dp1med medianp1  IS_WAR  lrgdpch  mildic royal  party  purge4yrs  purge4yrs2 purge4yrs3  ,   vce(bootstrap, rep(100))


* Model 4 in Table 3 
ologit purge4size3 dp1med  medianp1  lrgdpch  IS_WAR mildic royal  party   purge4yrs  purge4yrs2 purge4yrs3   ,vce(bootstrap, rep(100))

test _b[/cut1]=_b[/cut2]
test _b[/cut2]=_b[/cut3] 

ologit purge4size3 dp1med  medianp1  lrgdpch  IS_WAR mildic royal  party   purge4yrs  purge4yrs2 purge4yrs3   , or vce(bootstrap, rep(100))


**
** Appendix F  
**

** 
** Table 11  (Models 7 - 12)

logit purge4  dp1med medianp1  IS_WAR  lrgdpch  mildic royal  party  purge4yrs  purge4yrs2 purge4yrs3 if polity <6 & polity!=-88 & polity!=-77 & polity!=-66 ,   vce(bootstrap, rep(100))
 
logit purge4  dp1med medianp1  IS_WAR  lrgdpch  mildic royal  party  purge4yrs  purge4yrs2 purge4yrs3 if polity < -5 & polity!=-88 & polity!=-77 & polity!=-66 ,   vce(bootstrap, rep(100))
 
logit purge4  dp1med medianp1  IS_WAR  lrgdpch  mildic royal  party   purge4yrs  purge4yrs2 purge4yrs3  if gwf_nonautocracy2 != 1 & gwf_nonautocracy2 != 3 & gwf_nonautocracy2 != 4   , vce(bootstrap, rep(100))
 
 
ologit purge4size3 dp1med  medianp1  lrgdpch  IS_WAR mildic royal  party  purge4yrs  purge4yrs2 purge4yrs3 if polity <6 & polity!=-88 & polity!=-77 & polity!=-66 ,  vce(bootstrap, rep(100))

test _b[/cut1]=_b[/cut2]
test _b[/cut2]=_b[/cut3]
  
ologit purge4size3 dp1med  medianp1  lrgdpch  IS_WAR mildic royal  party  purge4yrs  purge4yrs2 purge4yrs3 if polity <6  & polity!=-88 & polity!=-77 & polity!=-66 ,  or vce(bootstrap, rep(100)) 


ologit purge4size3 dp1med  medianp1  lrgdpch  IS_WAR mildic royal  party  purge4yrs  purge4yrs2 purge4yrs3 if polity <-5  & polity!=-88 & polity!=-77 & polity!=-66 ,  vce(bootstrap, rep(100))

test _b[/cut1]=_b[/cut2]
test _b[/cut2]=_b[/cut3]
  
ologit purge4size3 dp1med  medianp1  lrgdpch  IS_WAR mildic royal  party  purge4yrs  purge4yrs2 purge4yrs3 if polity <-5  & polity!=-88 & polity!=-77 & polity!=-66 ,  or vce(bootstrap, rep(100)) 


ologit purge4size3 dp1med  medianp1  lrgdpch  IS_WAR mildic royal  party   purge4yrs  purge4yrs2 purge4yrs3 if gwf_nonautocracy2 != 1 & gwf_nonautocracy2 != 3 & gwf_nonautocracy2 != 4    ,vce(bootstrap, rep(100))

  
test _b[/cut1]=_b[/cut2]
test _b[/cut2]=_b[/cut3]
  
ologit purge4size3 dp1med  medianp1  lrgdpch  IS_WAR mildic royal  party   purge4yrs  purge4yrs2 purge4yrs3 if gwf_nonautocracy2 != 1 & gwf_nonautocracy2 != 3 & gwf_nonautocracy2 != 4    ,or vce(bootstrap, rep(100))

**
** Appendix D 
** 

** 
** Table 7 (Models 2, 4 and 6) 
  
logit purge4  dp1  meanp1   IS_WAR  lrgdpch  mildic royal  party   purge4yrs  purge4yrs2 purge4yrs3  ,   vce(bootstrap, rep(100))
 
logit purge9  dp1med medianp1  IS_WAR  lrgdpch  mildic royal  party  purge9yrs  purge9yrs2 purge9yrs3  ,   vce(bootstrap, rep(100))

ologit purge9size3 dp1med  medianp1  lrgdpch  IS_WAR mildic royal  party   purge9yrs  purge9yrs2 purge9yrs3   ,vce(bootstrap, rep(100))

test _b[/cut1]=_b[/cut2]
test _b[/cut2]=_b[/cut3]
  
ologit purge9size3 dp1med  medianp1  lrgdpch  IS_WAR mildic royal  party   purge9yrs  purge9yrs2 purge9yrs3   , or vce(bootstrap, rep(100))

 
 
  
 
**
** Appendix C 
** 
 

** Table 6 
  
logit coupexit lrgdpch  logmilex   mildic royal sparty mparty  failedcoup2_1   coupentry2 logt couplog,  robust cluster(ccode) 

logit coupexit asia  lamerica nafrme ssafrica lrgdpch  logmilex   mildic royal party  failedcoup2_1   coupentry2 logt couplog,  robust cluster(ccode) 
  
logit coupexit lag1purge4 lrgdpch  logmilex   mildic royal party  failedcoup2_1   coupentry2 logt couplog,  robust cluster(ccode) 

logit  purge4      logmilex IS_WAR  lrgdpch  mildic royal sparty mparty  failedcoup2   purge4yrs purge4yrs2 purge4yrs3  coupentry2 logt couplog,  robust cluster(ccode)  

logit  purge4   asia   lamerica nafrme ssafrica   logmilex IS_WAR  lrgdpch  mildic royal party  failedcoup2   purge4yrs purge4yrs2 purge4yrs3  coupentry2 logt couplog,  robust cluster(ccode)  
 
logit  purge9     logmilex IS_WAR  lrgdpch  mildic royal sparty  mparty failedcoup2   purge9yrs purge9yrs2 purge9yrs3  coupentry2 logt couplog,  robust cluster(ccode )  

logit  purge9  asia   lamerica nafrme ssafrica   logmilex IS_WAR  lrgdpch  mildic royal party  failedcoup2   purge9yrs purge9yrs2 purge9yrs3  coupentry2 logt couplog,  robust cluster(ccode)  

 

  
** 
** Appendix F (Other authoritarianism measures)
**
 
** 
** Table 9 
     
logit coupexit lrgdpch  logmilex   mildic royal party  failedcoup2_1   coupentry2 logt couplog if polity <6 & polity!=-88 & polity!=-77 & polity!=-66  ,   robust cluster(ccode) 
 
logit coupexit  IS_WAR chrgdpch lrgdpch  logmilex   mildic royal party  failedcoup2_1   coupentry2 logt couplog if polity <6 & polity!=-88 & polity!=-77 & polity!=-66  ,  robust cluster(ccode) 
 
** Excluding Anocracies 
 
logit coupexit lrgdpch  logmilex   mildic royal party  failedcoup2_1   coupentry2 logt couplog if polity < -5   & polity!=-88 & polity!=-77 & polity!=-66  ,   robust cluster(ccode) 
 
logit coupexit  IS_WAR chrgdpch lrgdpch  logmilex   mildic royal party  failedcoup2_1   coupentry2 logt couplog  if polity < -5   & polity!=-88 & polity!=-77 & polity!=-66,  robust cluster(ccode) 
 
** Geddes et al data 
* Exclude democracy, warlord and non-indepednent.  
 
logit coupexit lrgdpch  logmilex   mildic royal party  failedcoup2_1   coupentry2 logt couplog if gwf_nonautocracy2 != 1 & gwf_nonautocracy2 != 3 & gwf_nonautocracy2 != 4   ,  robust cluster(ccode) 
 
logit coupexit  IS_WAR chrgdpch lrgdpch  logmilex   mildic royal party  failedcoup2_1   coupentry2 logt couplog if gwf_nonautocracy2 != 1 & gwf_nonautocracy2 != 3 & gwf_nonautocracy2 != 4      , robust cluster(ccode) 

 
* Figure (Exporting to R)
logit coupexit lrgdpch  logmilex   mildic royal party  failedcoup2_1   coupentry2 logt couplog if polity <6 & polity!=-88 & polity!=-77 & polity!=-66  ,   robust cluster(ccode) 
drawnorm a b c d e f g h i j          , n(10000) means(e(b)) cov(e(V)) clear 
 
 
 
** 
** Table 10 
** 

* Polity A 
logit  purge4    logmilex IS_WAR    lrgdpch  mildic royal party  failedcoup2   purge4yrs purge4yrs2 purge4yrs3  coupentry2 logt couplog if polity <6 & polity!=-88 & polity!=-77 & polity!=-66  , robust cluster(ccode)  

logit  purge4 pastpurge4  logmilex IS_WAR  lrgdpch mildic royal  party failedcoup2   purge4yrs purge4yrs2 purge4yrs3  coupentry2 logt couplog if polity <6 & polity!=-88 & polity!=-77 & polity!=-66 ,   robust cluster(ccode)  
 
logit  purge9   logmilex     IS_WAR  lrgdpch    mildic royal  party    failedcoup2   purge9yrs purge9yrs2 purge9yrs3    coupentry2 logt couplog if polity <6 & polity!=-88 & polity!=-77 & polity!=-66 ,   robust cluster(ccode)  
 
logit  purge9   pastpurge4   logmilex  IS_WAR   lrgdpch    mildic royal party   failedcoup2   purge9yrs purge9yrs2 purge9yrs3  coupentry2 logt couplog if polity <6 & polity!=-88 & polity!=-77 & polity!=-66  ,   robust cluster(ccode)  

* Polity (B)   
logit  purge4    logmilex IS_WAR    lrgdpch  mildic royal party  failedcoup2   purge4yrs purge4yrs2 purge4yrs3  coupentry2 logt couplog if polity < -5   & polity!=-88 & polity!=-77 & polity!=-66 , robust cluster(ccode) 
 
logit  purge4 pastpurge4  logmilex IS_WAR  lrgdpch mildic royal  party failedcoup2   purge4yrs purge4yrs2 purge4yrs3  coupentry2 logt couplog if polity < -5 & polity!=-88 & polity!=-77 & polity!=-66 ,   robust cluster(ccode)  
  
logit  purge9   logmilex     IS_WAR  lrgdpch    mildic royal  party    failedcoup2   purge9yrs purge9yrs2 purge9yrs3    coupentry2 logt couplog if polity < -5 & polity!=-88 & polity!=-77 & polity!=-66 ,   robust cluster(ccode)  
 
logit  purge9   pastpurge4   logmilex  IS_WAR   lrgdpch    mildic royal party   failedcoup2   purge9yrs purge9yrs2 purge9yrs3  coupentry2 logt couplog if polity < -5 & polity!=-88 & polity!=-77 & polity!=-66  ,   robust cluster(ccode)  

* GWF 
logit  purge4    logmilex IS_WAR    lrgdpch  mildic royal party  failedcoup2   purge4yrs purge4yrs2 purge4yrs3  coupentry2 logt couplog if gwf_nonautocracy2 != 1 & gwf_nonautocracy2 != 3 & gwf_nonautocracy2 != 4   ,  robust cluster(ccode)  
 
logit  purge4 pastpurge4  logmilex IS_WAR  lrgdpch mildic royal  party failedcoup2   purge4yrs purge4yrs2 purge4yrs3  coupentry2 logt couplog if gwf_nonautocracy2 != 1 & gwf_nonautocracy2 != 3 & gwf_nonautocracy2 != 4   ,   robust cluster(ccode)   
 
logit  purge9   logmilex     IS_WAR  lrgdpch    mildic royal  party    failedcoup2   purge9yrs purge9yrs2 purge9yrs3    coupentry2 logt couplog if gwf_nonautocracy2 != 1 & gwf_nonautocracy2 != 3 & gwf_nonautocracy2 != 4  ,   robust cluster(ccode)  

logit  purge9   pastpurge4   logmilex  IS_WAR   lrgdpch    mildic royal party   failedcoup2   purge9yrs purge9yrs2 purge9yrs3  coupentry2 logt couplog if gwf_nonautocracy2 != 1 & gwf_nonautocracy2 != 3 & gwf_nonautocracy2 != 4     ,   robust cluster(ccode)  


*Figure 
logit  purge4    logmilex IS_WAR    lrgdpch  mildic royal party  failedcoup2   purge4yrs purge4yrs2 purge4yrs3  coupentry2 logt couplog if polity <6 & polity!=-88 & polity!=-77 & polity!=-66  , robust cluster(ccode)  
drawnorm a b c d e f g h i j k l m n   , n(10000) means(e(b)) cov(e(V)) clear


  
  
  
  
** 
** Appendix G (Failed Coup) 
** 
    

use "C:\Users\Jun\Dropbox\Elite Purge Project\CPS Final\CPS_Elitepurge_Sudduth.dta", clear  
xtset leadid2 year
 
  
gen ln_decayfailed = log(decayfailed  +1)  
gen ln_decayfailed2 = log(decayfailed2 +1)  



**
** Table 13 
** 
 
logit coupexit    lrgdpch  logmilex   mildic royal party                   coupentry2 logt couplog  failedcoup2_1  ln_decayfailed2  ,  robust cluster(ccode) 
 
logit coupexit  IS_WAR chrgdpch lrgdpch  logmilex   mildic royal party     coupentry2 logt couplog  failedcoup2_1  ln_decayfailed2  ,  robust cluster(ccode) 
 
 
logit  failedcoup   lrgdpch  logmilex   mildic royal party      coupentry2 logt couplog failedcoup2_1  ln_decayfailed2  ,  robust cluster(ccode)

logit failedcoup  IS_WAR chrgdpch lrgdpch  logmilex   mildic royal party     coupentry2 logt couplog  failedcoup2_1  ln_decayfailed2  ,  robust cluster(ccode) 
  
#delimit;
heckprobit coupexit failedcoup2_1  ln_decayfailed2  lrgdpch  logmilex  mildic royal   , robust cluster(ccode) 
sel(anycoup  = failedcoup2_1  ln_decayfailed2  lrgdpch  logmilex   mildic royal party   coupentry2 logt couplog   ); 
 
 
** 
** Table 12 
**           

* Pr(Failed Coup)

drop b*   
estsimp logit failedcoup   lrgdpch  logmilex   mildic royal party      coupentry2 logt couplog failedcoup2_1  ln_decayfailed2   ,   robust cluster(ccode)   sims(10000)   
  
sum  failedcoup2_1   ln_decayfailed2, detail 
tabulate    failedcoup2_1
tabulate ln_decayfailed2   

* Pr(Purge) when there was no failed coup before 

setx  failedcoup2_1 0 ln_decayfailed2  0    
simqi  
   
setx  failedcoup2_1 1 ln_decayfailed2 log(2)
simqi 

display (    .7034275    -  .4725138   )/(   .4725138   )*100
* 48.869197
   
setx  failedcoup2_1 1 ln_decayfailed2 log(3)
simqi 
   
  
display (    .6537308   -  .4725138   )/(   .4725138   )*100
* 38.351684


setx  failedcoup2_1 1 ln_decayfailed2 log(4)
simqi 
    
display (     .6151869  -  .4725138   )/(   .4725138   )*100


setx  failedcoup2_1 1 ln_decayfailed2 log(5)
simqi 
   
	 
display (  .5839256 -  .4725138   )/(   .4725138   )*100		
			
setx  failedcoup2_1 1 ln_decayfailed2 log(6)
simqi 

display (  .5578269  -  .4725138   )/(   .4725138   )*100		
	
   
**  First Difference 

 
setx 
simqi, fd(pr) changex(failedcoup2_1 0 1 ln_decayfailed2 0 log(2)     ) level(99) 
    
	 
simqi, fd(pr) changex(failedcoup2_1 0 1 ln_decayfailed2 0 log(2)     ) level(90) 

  
	
setx 
simqi, fd(pr) changex(failedcoup2_1 0 1 ln_decayfailed2 0 log(3)     ) level(99) 
   
simqi, fd(pr) changex(failedcoup2_1 0 1 ln_decayfailed2 0 log(3)     ) level(90) 
       
setx 
simqi, fd(pr) changex(failedcoup2_1 0 1 ln_decayfailed2 0  log(4)     ) level(95) 
    		 
simqi, fd(pr) changex(failedcoup2_1 0 1 ln_decayfailed2 0  log(4)     ) level(90) 

  
setx 

simqi, fd(pr) changex(failedcoup2_1 0 1 ln_decayfailed2 0 log(5)     ) level(90) 
 
setx 
simqi, fd(pr) changex(failedcoup2_1 0 1 ln_decayfailed2 0 log(6)     ) level(90) 

	     
	  
	  
	  
** Pr(Success|Attempt) 
 

#delimit;
heckprobit coupexit failedcoup2_1  ln_decayfailed2  lrgdpch  logmilex  mildic royal   , robust cluster(ccode) 
sel(anycoup  = failedcoup2_1  ln_decayfailed2  lrgdpch  logmilex   mildic royal party   coupentry2 logt couplog   ); 
 
*heckprob scoup incid  gw_lrgdpch lsolpay
matrix params = e(b)
*Pulls the beta values for later calcualtions */

matrix P = e(V) 
*Pulls the variance matrix for later calculations */

collapse (mean)     lrgdpch  logmilex   logt     (median) mildic royal party 
  
generate coupentry2= 0 
generate couplog= 0 

  
expand 10000

drawnorm beta1-beta18 rho, means(params) cov(P)
    *This command draws the betas and other parameters from the model, you must adjust this line of the total number of variabels in your model (including constants).  Currently sent to draw for 12 variables (plus 2 constants) */

sum rho beta*

correlate rho beta*, cov

gen simrho = (exp(2*rho)-1)/(exp(2*rho)+1)

* Set the variables : all means or medians except your key IV  
 
generate select1 =  beta18 + (beta17*  couplog) + (beta16 * logt) + (beta15*coupentry2  ) + (beta14*party) + (beta13*royal) + (beta12* mildic ) + (beta11*  logmilex  ) + (beta10* lrgdpch )  + (beta9*0) + (beta8*0)
 
* No past failed coup    
generate outcome1 = beta7 +  (beta6 *royal) + (beta5*mildic ) + (beta4 *logmilex ) + (beta3* lrgdpch  ) + (beta2* 0 ) + (beta1*0)
* Just after failed coup  
generate outcome2 = beta7 +  (beta6 *royal) + (beta5*mildic ) + (beta4 *logmilex ) + (beta3* lrgdpch  ) + (beta2* log(2) ) + (beta1*1)
* 3 years afeter failed coup
generate outcome3 = beta7 +  (beta6 *royal) + (beta5*mildic ) + (beta4 *logmilex ) + (beta3* lrgdpch  ) +  (beta2* log(3) ) + (beta1*1)
* 5 years after failed coup 
generate outcome4 = beta7 +  (beta6 *royal) + (beta5*mildic ) + (beta4 *logmilex ) + (beta3* lrgdpch  ) + (beta2* log(4) ) + (beta1*1)
 * 7 years after failed coup 
generate outcome5 = beta7 +  (beta6 *royal) + (beta5*mildic ) + (beta4 *logmilex ) + (beta3* lrgdpch  ) + (beta2* log(5) ) + (beta1*1)
* 10 years after failed coup 
generate outcome6 = beta7 +  (beta6 *royal) + (beta5*mildic ) + (beta4 *logmilex ) + (beta3* lrgdpch  ) + (beta2* log(6) ) + (beta1*1)
 

generate conditionalp1 = binorm(outcome1, select1, simrho)/ normal(select1)

generate conditionalp2= binorm(outcome2, select1, simrho)/ normal(select1)

generate conditionalp3= binorm(outcome3, select1, simrho)/ normal(select1)

generate conditionalp4= binorm(outcome4, select1, simrho)/ normal(select1)

generate conditionalp5= binorm(outcome5, select1, simrho)/ normal(select1)

generate conditionalp6= binorm(outcome6, select1, simrho)/ normal(select1)




generate joinp1 = binorm(outcome1, select1, simrho)
generate joinp2= binorm(outcome2, select1, simrho)
generate joinp3= binorm(outcome3, select1, simrho)
generate joinp4= binorm(outcome4, select1, simrho)
generate joinp5= binorm(outcome5, select1, simrho)
generate joinp6= binorm(outcome6, select1, simrho)

 

generate fd_con= conditionalp2 - conditionalp1  
generate fd_con2= conditionalp3 - conditionalp1 
generate fd_con3= conditionalp4 - conditionalp1 
generate fd_con4= conditionalp5 - conditionalp1 
generate fd_con5= conditionalp6 - conditionalp1  


sum conditionalp1, detail 
sum conditionalp2, detail 

sum conditionalp3, detail  

sum conditionalp4, detail 
sum conditionalp5, detail 

sum conditionalp6, detail 

 
 * percentage changes 
 
display (  .1985642  -   .4845722   )/(    .4845722  )*100
 
display (  .2682581 -   .4845722   )/(    .4845722  )*100
 
display (   .3308835  -   .4845722   )/(    .4845722  )*100
 
display (  .3855567  -   .4845722   )/(    .4845722  )*100

display (   .4326042  -   .4845722   )/(    .4845722  )*100


 sum fd_con, detail
 sum fd_con2, detail
 sum fd_con3, detail
 sum fd_con4, detail
 sum fd_con5, detail


 
 


** 
** Table 15 
* failedcoup2 : =1 for the year of and years after a failed coup experience
    

use "C:\Users\Jun\Dropbox\Elite Purge Project\CPS Final\CPS_Elitepurge_Sudduth.dta", clear  
xtset leadid2 year
  
gen ln_decayfailed = log(decayfailed  +1)  
gen ln_decayfailed2 = log(decayfailed2 +1)  


logit  purge4 pastpurge4  logmilex IS_WAR   lrgdpch mildic royal  party    purge4yrs purge4yrs2 purge4yrs3  coupentry2 logt couplog failedcoup2  ln_decayfailed  ,   robust cluster(ccode) 
  
logit  purge4 pastpurge4  logmilex IS_WAR   lrgdpch mildic royal  sparty  mparty  purge4yrs purge4yrs2 purge4yrs3  coupentry2 logt couplog failedcoup2 ln_decayfailed  ,   robust cluster(ccode) 
  
logit  purge9   pastpurge4   logmilex  IS_WAR  lrgdpch    mildic royal party   purge9yrs purge9yrs2 purge9yrs3  coupentry2 logt couplog failedcoup2 ln_decayfailed ,  robust cluster(ccode) 
  
logit  purge9   pastpurge4   logmilex  IS_WAR  lrgdpch    mildic royal sparty mparty   purge9yrs purge9yrs2 purge9yrs3  coupentry2 logt couplog failedcoup2 ln_decayfailed ,  robust cluster(ccode) 


**
** Table 16 

drop b*   
estsimp logit  purge4 pastpurge4  logmilex IS_WAR   lrgdpch mildic royal  party    purge4yrs purge4yrs2 purge4yrs3  coupentry2 logt couplog failedcoup2 ln_decayfailed  ,   robust cluster(ccode)   sims(10000)
 
 
sum  failedcoup2 ln_decayfailed, detail 
tabulate    failedcoup2 
tabulate ln_decayfailed   

* Pr(Purge) when there was no failed coup before 

setx  failedcoup2 0 ln_decayfailed 0
simqi  

simqi , level(90) 
 
* Pr(Purge) immediately after failed coup (t) 

setx  failedcoup2 1 ln_decayfailed log(2)      
simqi  
   
display (   .1930823     - .0564403   )/(  .0564403    )*100
  
 
* Pr(Purge) immediately after failed coup (t +1 ) 

setx  failedcoup2 1 ln_decayfailed log(3)      
simqi 
    
display (   .1412772   - .0564403   )/(  .0564403    )*100
  
	
setx  failedcoup2 1 ln_decayfailed log(4)      
simqi 
  
display (    .1123371       - .0564403   )/(  .0564403    )*100
 

setx  failedcoup2 1 ln_decayfailed log(5)      
simqi 
	  
display (      .0938624        - .0564403   )/(  .0564403    )*100
 
	
setx  failedcoup2 1 ln_decayfailed log(6)      
simqi 
	  
display (    .0810311      - .0564403   )/(  .0564403    )*100
  
	 
**  First Difference 
 
setx 
simqi, fd(pr) changex(failedcoup2 0 1 ln_decayfailed log(1) log(2)     ) level(99) 
    		   
simqi, fd(pr) changex(failedcoup2 0 1 ln_decayfailed log(1) log(2)     ) level(90) 
  
setx 
simqi, fd(pr) changex(failedcoup2 0 1 ln_decayfailed log(1) log(3)     ) level(99) 
  
simqi, fd(pr) changex(failedcoup2 0 1 ln_decayfailed log(1) log(3)     ) level(90 ) 
   
setx 
simqi, fd(pr) changex(failedcoup2 0 1 ln_decayfailed log(1) log(4)     ) level(99) 
  
simqi, fd(pr) changex(failedcoup2 0 1 ln_decayfailed log(1) log(4)     ) level(90) 
  		   
setx 
simqi, fd(pr) changex(failedcoup2 0 1 ln_decayfailed log(1) log(5)     ) level(99) 
   
simqi, fd(pr) changex(failedcoup2 0 1 ln_decayfailed log(1) log(5)     ) level(90 ) 
 
setx 
simqi, fd(pr) changex(failedcoup2 0 1 ln_decayfailed log(1) log(6)     ) level(90) 

setx 
simqi, fd(pr) changex(failedcoup2 0 1 ln_decayfailed log(1) log(11)   ) level(90)  


* END;    
 
  